package com.dongbo.recorder.screenrecord.widget;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.dongbo.recorder.screenrecord.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AgreementDialog extends Dialog {

    @BindView(R.id.btnKnow)
    TextView btnKnow;


    private OnDialogEventListener onDialogEventListener;
    private Context context;

    /**
     * @param context
     * @param themeResId
     * @param onDialogEventListener dialog 事件回调
     */
    public AgreementDialog(Context context,
                           int themeResId,
                           OnDialogEventListener onDialogEventListener) {
        super(context, themeResId);
        this.context = context;
        this.onDialogEventListener = onDialogEventListener;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_agreement);
        ButterKnife.bind(this);
        btnKnow.setSelected(true);
        setCancelable(false);
    }

    @OnClick({R.id.xieyi, R.id.yinsi, R.id.btnKnow, R.id.btnCancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.xieyi:
                if (onDialogEventListener != null) {
                    onDialogEventListener.onClicked(1);
                }
                break;
            case R.id.yinsi:
                if (onDialogEventListener != null) {
                    onDialogEventListener.onClicked(2);
                }
                break;
            case R.id.btnKnow:
                if (onDialogEventListener != null) {
                    onDialogEventListener.onKonw();
                }
                dismiss();
                break;
            case R.id.btnCancel:
                if (onDialogEventListener != null) {
                    onDialogEventListener.onCancel();
                }
                dismiss();
                break;
        }
    }

    public interface OnDialogEventListener {
        void onClicked(int v);

        void onKonw();

        void onCancel();
    }

    public void destroy() {
        onDialogEventListener = null;
        context = null;
        dismiss();
        cancel();
    }

//    @Override
//    public void setCanceledOnTouchOutside(boolean cancel) {
//        cancel = false;
//        super.setCanceledOnTouchOutside(cancel);
//    }
}